#ifndef _BINARYTREE
#define _BINARYTREE

#include "Node.h"
#include <string.h>

#define BUFSIZE 512	// memoria alocata 4kB

/* A binary tree implemented using arrays. It cannot be implemented using pointers because it should be a contiguous space for mapping shared memory*/

class BinaryTree
{
	Node nodeNULL;
	short int findFree();		//  find a free offset in  the array
	short int FindMin(short int);//  find the minimum in the subtree with the root in the root offset
public:

	Node* arb;					// the array where is the tree stored

	BinaryTree();				// contructor

	~BinaryTree();				// destructor

	void setArbMemory(Node* vArb);	// sets the memory space where the tree is saved -  this function is used  by the server
	void cloneArb(Node* vArb);		// clones the tree- this function is used by the client
	void addNode(int x);			// add a node in the tree
	int equal(Node n1,Node n2);		// verifies if two nodes are equal

	short int Delete(int x,short int root);// delete a note from the tree
	void Clear();						   // the tree becomes empty
	
	void makeLinks(short int root,short int i);// integrates a node in the tree 
	void printTree(short int root);			// displays the tree -= this function is used  by the client
	
};
#endif